package cn.imnu.legalaid.mapper;

import cn.imnu.legalaid.dto.User.PublicUserInfoDTO;
import cn.imnu.legalaid.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author 18498
* @description 针对表【users(用户表)】的数据库操作Mapper
* @createDate 2025-09-19 17:49:09
* @Entity cn.imnu.legalaid.entity.Users
*/
public interface UsersMapper extends BaseMapper<User> {

    /**
     * 获取单个用户的公开信息
     */
    @Select("SELECT id, username, real_name as realName, avatar_url as avatarUrl, role as userType " +
            "FROM users WHERE id = #{userId}")
    PublicUserInfoDTO selectPublicUserInfo(@Param("userId") Integer userId);

    /**
     * 批量获取用户的公开信息
     */
    @Select("<script>" +
            "SELECT id, username, real_name as realName, avatar_url as avatarUrl, role as userType " +
            "FROM users WHERE id IN " +
            "<foreach collection='userIds' item='id' open='(' separator=',' close=')'>#{id}</foreach>" +
            "</script>")
    List<PublicUserInfoDTO> selectPublicUserInfoBatch(@Param("userIds") List<Integer> userIds);

    /**
     * 获取律师列表的公开信息
     */
    @Select("<script>" +
            "SELECT id, username, real_name as realName, avatar_url as avatarUrl, role as userType " +
            "FROM users WHERE role = 'lawyer' " +
            "<if test='specialty != null and specialty != \"\"'>" +
            "AND specialties LIKE CONCAT('%', #{specialty}, '%') " +
            "</if>" +
            "ORDER BY rating DESC, experience DESC " +
            "LIMIT #{offset}, #{size}" +
            "</script>")
    List<PublicUserInfoDTO> selectPublicLawyersInfo(@Param("offset") Integer offset, 
                                                    @Param("size") Integer size, 
                                                    @Param("specialty") String specialty);
}




